package 序列化;

import java.io.*;
import java.util.ArrayList;

public class Demo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\jiuye\\dey11\\src\\序列化\\aaa.txt"));
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student("张三", "22"));
        list.add(new Student("李四", "21"));
        list.add(new Student("王五", "25"));
        list.add(new Student("赵六", "24"));
        oos.writeObject(list);
        oos.close();
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\jiuye\\dey11\\src\\序列化\\aaa.txt"));
        ArrayList<Student> students = (ArrayList<Student>) ois.readObject();
        for (Student student : students) {
            System.out.println(student.getName() + student.getAge());
        }
    }
}
